package com.ks.member.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.OperateIndentifyTransfer;
import com.ks.core.dto.SearchCriteriaBase;

import com.ks.member.aop.Author;
import com.ks.member.controller.dto.LoginRequest;
import com.ks.member.controller.dto.MemberBaseDto;
import com.ks.member.controller.dto.MemberRequest;
import com.ks.member.entity.MemberBase;
import com.ks.member.service.IMemberBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 会员系统  用户基本信息 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-22
 */
@RestController
@RequestMapping("/memberBase")
@Api(value = "微会员管理模块", description = "微会员管理模块")
public class MemberBaseController extends _ControllerBase {

    @Autowired
    private IMemberBaseService iMemberBaseService;


    @PostMapping("/getMemberBaseList")
    @ApiOperation(value = "微会员用户列表查询接口", notes = "cUserLevel,根据会员等级查询")
    @Author
    public Object getMemberBaseList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> memberBaseList = iMemberBaseService.getMemberBaseList(getContext(),searchCriteriaBase);
        return Result.success(memberBaseList);
    }

    @PostMapping("/getMemberBaseUserCount")
    @ApiOperation(value = "租户注册用户数", notes = "租户注册用户数")
    public Object getMemberBaseUserCount(){
        Map<String, Object> memberBaseAdminCount = iMemberBaseService.getMemberBaseUserCount(getContext());
        return Result.success(memberBaseAdminCount);
    }

    @PostMapping("/getMemberBaseAdminCount")
    @ApiOperation(value = "系统注册用户数", notes = "系统注册用户数")
    public Object getMemberBaseAdminCount(){
        Map<String, Object> memberBaseAdminCount = iMemberBaseService.getMemberBaseAdminCount(getContext());
        return Result.success(memberBaseAdminCount);
    }

    @PostMapping("/getMemberBaseUserAdminCount")
    @ApiOperation(value = "系统用户每日注册数量查询", notes = "系统用户每日注册数量查询")
    public  Object getMemberBaseUserAdminCount(){
        Map<String, Object> memberBaseUserAdminCount = iMemberBaseService.getMemberBaseUserAdminCount(getContext());
        return Result.success(memberBaseUserAdminCount);
    }

    @PostMapping("/getMemberBaseAddressCount")
    @ApiOperation(value = "租户会员地区占比图", notes = "租户会员地区占比图")
    public  Object getMemberBaseAddressCount(){
        Map<String, Object> memberBaseUserAdminCount = iMemberBaseService.getMemberBaseAddressCount(getContext());
        return Result.success(memberBaseUserAdminCount);
    }



    @PostMapping("/getMemberBaseAdminList")
    @ApiOperation(value = "系统后台微会员用户列表查询接口", notes = "系统后台微会员用户列表查询接口")
    public Object getMemberBaseAdminList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> memberBaseList = iMemberBaseService.getMemberBaseAdminList(getContext(),searchCriteriaBase);
        return Result.success(memberBaseList);
    }

    @PostMapping("/addStartMember")
    @ApiOperation(value = "推荐成为明星会员", notes = "cUserType,改变会员等级类型")
    @Author
    public Object addStartMember(@RequestBody MemberBase memberBase) {
        int resultMap = iMemberBaseService.addStartMember(getContext(),memberBase);
        return Result.success(resultMap);
    }

 /*   @PostMapping("/login")
    @ApiOperation(value = "微会员应用端登录接口", notes = "OpenID:微信的OpenID;TenantID:租户代码")
    @Author
    public Object Login(@RequestBody LoginRequest loginRequest) {
        Map<String, Object> login = iMemberBaseService.login(loginRequest.getOpenID(), loginRequest.getTenantID());
        return Result.success(login);
    }
*/
    @PostMapping("/signOut")
    @ApiOperation(value = "微会员应用端退出登录接口", notes = "微会员应用端退出登录接口")
    @Author
    public Object SignOut() {
        int i = iMemberBaseService.SignOut(this.GetAuthorToken());
        return Result.success(i);
    }

    @PostMapping("/LognOut")
    @ApiOperation(value = "微会员应用端注销会员接口", notes = "微会员应用端注销会员接口")
    @Author
    public Object LognOut() {
        int i = iMemberBaseService.LognOut(this.GetAuthorToken());
        return Result.success(i);
    }

    @PostMapping("/ResetPassword")
    @ApiOperation(value = "微会员重置密码", notes = "indentifyCode放验证码,note放新密码")
    @Author
    public Object ResetPassword(@RequestBody OperateIndentifyTransfer operate) {
        int i = iMemberBaseService.ResetPassword(getContext(),operate);
        return Result.success(i);
    }

    @PostMapping("/BuindTel")
    @ApiOperation(value = "微会员绑定手机号", notes = "indentifyCode放验证码,note放手机号")
    @Author
    public Object BuindTel(@RequestBody OperateIndentifyTransfer operate) {
        int i = iMemberBaseService.BuindTel(getContext(),operate);
        return Result.success(i);
    }

    @PostMapping("/getMemberList")
    @ApiOperation(value = "推荐明星会员查询接口", notes = "推荐明星会员查询接口")
    @Author
    public Object getMemberList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> memberList = iMemberBaseService.getMemberList(getContext(),searchCriteriaBase);
        return Result.success(memberList);
    }

    @PostMapping("/queryMemberBase")
    @ApiOperation(value = "会员个个信息查询接口", notes = "会员个个信息查询接口")
    @Author
    public Object queryMember(@RequestBody MemberRequest request) {
        MemberBase queryMember = iMemberBaseService.getQueryMember(getContext(), request.getId());
        return Result.success(queryMember);
    }


    @PostMapping("/queryMemberInfo")
    public MemberBase queryMemberInfo(@RequestParam("userId") int userId) {
        MemberBase queryMember = iMemberBaseService.getInfo(userId);
        return queryMember;
    }


    @PostMapping("/updateMemberBase")
    @ApiOperation(value = "修改会员信息", notes = "修改会员信息")
    @Author
    public Object getMemberList(@RequestBody MemberBase memberBase) {
        int i = iMemberBaseService.updateMember(getContext(), memberBase);
        return Result.success(i);
    }

    @PostMapping("/updateMemberBasePassword")
    @ApiOperation(value = "修改会员密码", notes = "传旧密码和新密码")
    @Author
    public Object updateMemberBasePassword(@RequestBody MemberBaseDto memberBaseDto) {
        int i = iMemberBaseService.updateMemberPassword(getContext(), memberBaseDto.getPassword(),memberBaseDto.getNewPassword());
        return Result.success(i);
    }

    @PostMapping("/bindMobile")
    @ApiOperation(value = "会员绑定手机号", notes = "传手机号和验证码即可")
    @Author
    public Object bindMobile(@RequestBody MemberBaseDto memberBaseDto) {
        int i = iMemberBaseService.bindMobile(getContext(), memberBaseDto.getMobile(),memberBaseDto.getCode());
        return Result.success(i);
    }

}

